home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Demos / A.D. Software / OOFILE / Buildable, limited OOFILE / samples / ooftst16.cpp < prev    next >
C/C++ Source or Header  |  1996-03-21  |  2KB  |  78 lines

  1. // Copyright 1994 A.D. Software. All Rights Reserved
  2.  
  3. // OOFTEST 16
  4.  
  5. // this sample modifies related data
  6. // including demonstrating the caching of related records
  7. // as would typically be used in a GUI environment
  8.  
  9. // Simple stream I/O is used to interact with the user.
  10. #include "oofile.hpp"
  11.  
  12.  
  13. #include "ooftst16.inc"
  14.  
  15. int main()
  16. {
  17.     cout << "OOFILE Validation Suite - Test 16\n"
  18.          << "Simple test to demonstrate updating related fields" << endl
  19.          << "using a similar database to ooftst06 but with direct OID relationships" << endl;
  20.  
  21.     if (dbConnect::fileExists("ooftst16.db")) {
  22.         theDB.openConnection("ooftst16.db");
  23.         Patients.deleteAll();
  24.     }
  25.     else {
  26.         theDB.newConnection("ooftst16.db");
  27.     }
  28.     Patients.AddTestData();
  29.     
  30.     Patients.selectAll();
  31.     dbView smithVisits(Patients.Visits); 
  32.     smithVisits << Patients.Visits->VisitDate << Patients.Visits->Why; 
  33.  
  34. cout << "Now dumping the entire Visits file: " << endl << Visits;
  35.  
  36.     Patients.search(Patients.LastName=="Smith");
  37.     cout << "Dumping Smith and his visits: " << endl 
  38.          << Patients << endl 
  39.          << smithVisits << endl;
  40.     
  41.     cout << "changing the first reason to 'Computer-Induced Sanity' " << endl;
  42.     Patients.Visits->gotoRecord(0);
  43.     Patients.Visits->Why = "Computer-Induced Sanity";
  44.     
  45.     cout << "changing the second reason to 'Funny Views' " << endl;
  46.     smithVisits.source()->gotoRecord(1);  // test navigating via the view
  47.     smithVisits.field(1) = "Funny Views";
  48.  
  49.     Patients.saveRecord();  // save both changes
  50.  
  51.     cout << "Dumping Smith and changed visits: " << endl 
  52.          << Patients << endl 
  53.          << smithVisits << endl;
  54.  
  55.     Patients.AddVisit("14/2/1995", "Anxiety Attacks");
  56.     
  57. // now change to another related record - our new one should be cached
  58.     smithVisits.source()->gotoRecord(1);  
  59.     smithVisits.field(1) = "Changed Again";
  60.  
  61. // return to the new record (in the cache) and update it    
  62.     smithVisits.source()->gotoRecord(2);  
  63.     smithVisits.field(0) = "15/2/1994";
  64.     
  65.     Patients.saveRecord(); 
  66.     cout << "Dumping Smith and visits with added visit: " << endl 
  67.          << Patients << endl 
  68.          << smithVisits << endl;
  69.          
  70.     cout << "Now dumping the entire database: " << endl << theDB;
  71.     
  72.     cout << "Description of database schema: " << endl;
  73.     theDB.describe(cout);
  74.     
  75.     cout << "done" << endl;
  76.  
  77.     return EXIT_SUCCESS;
  78. }